# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=webshag
pkgver=1.10
pkgrel=10
groups=('blackarch' 'blackarch-fuzzer' 'blackarch-scanner' 'blackarch-webapp')
pkgdesc='A multi-threaded, multi-platform web server audit tool.'
url='http://www.scrt.ch/en/attack/downloads/webshag'
arch=('any')
license=('GPL3')
depends=('python2' 'wxpython' 'nmap' 'nikto')
makedepends=('dos2unix')
source=("http://www.scrt.ch/outils/webshag/ws${pkgver//.}.tar.gz"
        "$pkgname.install"
        'core_file.patch')
sha512sums=('10650325f13f7e1df0ac416ab1b91cb26801b676'
          'f8daee3d9fd1db2a08336e036b423dbe1e857f09'
          '4e0f7b4a068b82fa23f32fcd87e5ffdb7dfbb6e9')
install="$pkgname.install"

prepare(){
  find . -type f -iname "*" |
  while read i ; do
    dos2unix $i
  done

  grep -iRl python "$srcdir" |
  xargs sed -i 's|#!.*/usr/bin/python|#!/usr/bin/python2|;s|#!.*/usr/bin/env python$|#!/usr/bin/env python2|'

  cd $pkgname/core

  patch < "$srcdir/core_file.patch"
}

package() {
  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  cp -La --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/webshag_cli" << EOF
#!/bin/sh
exec /usr/share/$pkgname/webshag_cli.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/webshag_cli"

cat > "$pkgdir/usr/bin/webshag_gui" << EOF
#!/bin/sh
exec /usr/share/$pkgname/webshag_gui.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/webshag_gui"
}

